<?php
/*
 * 微网站主控制器
 * breeze @ 2015.12.3
 */
//require_once dirname(__FILE__).'/../../include/mdb.class.php';
class Index_con extends Lxbase {
    
    /*
     * 默认执行的测试方法
     */
	public function index() {
		if("qiyue.zhongsou.com"==$_SERVER['HTTP_HOST']){
			header("location:http://vq.zhongsou.com".$_SERVER['REQUEST_URI']);
		}
		exit;
	}
	
	/*
	 * 测试数据库方法
	 */
	public function db() {
	    $path = dirname(__FILE__).'/../../templates/tmpl/themes';
	    if (!is_dir($path)) {
	        
	    }
	}
	
	//支付宝支付页
	public function alipay(){
	    $type = $_GET['type'];// direct(即时到账)，escow(担保交易)
	    
	    $sn=$_GET["sn"];
	    if(empty($sn)){die("{$sn}订单信息错误");}
	    $uinfo=$_SESSION["uinfo"];
	    //订单信息
	    $orderinfo=$this->viewdata("id,uid,hid,order_sn,amount,in_time,out_time,info","hotel_order","where order_sn='{$sn}'");
	    if(empty($uinfo)){
	        header("location:?a=login&hid={$orderinfo['hid']}");
	        exit;
	    }
	    if(empty($orderinfo)){die("订单信息错误");}
	    //酒店信息
	    $hotelinfo=$this->viewdata("*","hotel","where id={$orderinfo['hid']}");
	    $userid=$hotelinfo["uid"];
	    //住房信息
	    $info = unserialize($orderinfo["info"]);
	    $tname = $this->oncedata("name","hotel_type","where id={$info[0]['tid']}");
	    $pname = $this->oncedata("name","hotel_type_project","where id={$info[0]['pid']}");
	    //微信信息
	    $wxguest = $this->viewdata("*","wxguest","where userid={$userid} and uid='".$uinfo['uid']."'");
	
	    //统一支付接口
	    $data["userid"]=$userid;
	    $data["sn"]=$sn;
	    $data["title"] = $tname." ".$pname;
	    $data["body"]=$tname;
	    $data["price"]=$orderinfo["amount"];
	    $data["url"]=$this->basehost."minisite/hotel/?a=notify&orderid={$orderinfo['id']}";
	    $data["ip"]=getuserip();
	    
	    $data['type'] = $type;//即时到账
	    //if(!empty($wxguest["openid"])){$data["openid"]=$wxguest["openid"];}
	    $paydata=base64_encode(json_encode($data));
	    header("location:{$this->basehost}api/alipay.php?paydata={$paydata}");
	    exit;
	}
	
	public function test(){
	    $t = $_GET['t'];
	    $data["userid"] = 1;
	    $data["sn"]     = "Y20151222".time();
	    $data["title"]  = "测试订单";
	    $data["body"]   = "http://kaifa.zq.zhongsou.com/index.php";//跳转链接
	    $data["price"]  = 0.01;
	    $data["url"]    = "http://kaifa.zq.zhongsou.com/index.php";
	    $data["ip"]     = getuserip();
	    if ($t == 0) {
	       $data['type']   = 'direct';//即时到账
	    } else {
	       $data['type']   = 'escow';//担保交易
	    }
	    
	    $data=base64_encode(json_encode($data));
	    header("location:http://kaifa.zq.zhongsou.com/api/alipay.php?paydata={$data}");
	    exit;
	}
}
